package com.strongbj.iot.devices.newlight.response.handle;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.strongbj.core.message.IMessageHandle;
import com.strongbj.core.util.ByteUtil;
import com.strongbj.iot.devices.newlight.message.NewLightReaderMessage;
import com.strongbj.iot.devices.newlight.response.common.HandleTimeStamp;

import io.netty.channel.ChannelHandlerContext;

/**
 * 0x32，信道释放 
 * @author lei_w
 *
 */
public class ChannelDisposibleResponseHandle implements IMessageHandle<NewLightReaderMessage, Object> {

	private static Logger logger = LogManager.getLogger(ChannelStateApplyResponseHandle.class.getName());
	
	@Override
	public boolean isHandle(NewLightReaderMessage t) {
		if (Integer.valueOf("32", 16).byteValue() == t.getType()) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public Object handle(ChannelHandlerContext ctx, NewLightReaderMessage t) {
		
		String hostNumber = ByteUtil.byteArrToHexString(t.getAddress()); // reader 地址码
		String timeStamp = ByteUtil.byteArrToHexString(t.getTime()); // 时间戳
		
		String log = "\r\n===================================================" +
					"\r\n收到信道释放报文：" + 
					"\r\nREADER地址码：" + hostNumber + 
					"\r\n时间戳：" + HandleTimeStamp.handle(timeStamp);
		logger.info(log);
		return null;
	}

	@Override
	public void destory() {
		// TODO Auto-generated method stub
		
	}

}
